﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Threading.Tasks;
using System.Windows.Forms;
using CCWin.SkinControl;
using NikeSale.Bll;
using static NikeSale.Bll.DBSelect;
using NikeSale.Models;
using System.Diagnostics;

namespace NikeSale.Ull
{
    public partial class MainForm : Form
    {
        /// <summary>
        /// 当前登陆的用户信息
        /// </summary>
        private LoginInfo User { get; set; }

        public MainForm(LoginInfo info)
        {
            this.User = info;
            InitializeComponent();
            Animation.窗体动画.Enter_Animate(this.Handle, Animation.Enter_Animations.淡入, 1500);
            CheckForIllegalCrossThreadCalls = false;
            Initialize();
            this.timer_tik.Start();
            this.lb_Welcome.Text = $"{User.UserName}({User.Role}) 欢迎您";
            this.bt_UserInfo.Text = User.UserName;
        }

        #region 动画事件
        //按钮移入移出动画
        private void bt_MouseEnter_SuspendedAnimation(object sender, EventArgs e)
        {
            SkinButton bt = sender as SkinButton;
            bt.ForeColor = Color.Gold;
            bt.ImageSize = new Size(bt.ImageSize.Width + 6, bt.ImageSize.Height + 6);
        }
        private void bt_MouseLeave_SuspendedAnimation(object sender, EventArgs e)
        {
            SkinButton bt = sender as SkinButton;
            bt.ForeColor = Color.White;
            bt.ImageSize = new Size(bt.ImageSize.Width - 6, bt.ImageSize.Height - 6);
            bt.BackColor = Color.Transparent;
        }

        //按钮按下弹起动画
        private void bt_MouseDown_ClickAnimation(object sender, MouseEventArgs e)
        {
            SkinButton bt = sender as SkinButton;
            bt.ImageSize = new Size(bt.ImageSize.Width - 6, bt.ImageSize.Height - 6);
        }
        private void bt_MouseUP_ClickAnimation(object sender, MouseEventArgs e)
        {
            SkinButton bt = sender as SkinButton;
            bt.ImageSize = new Size(bt.ImageSize.Width + 6, bt.ImageSize.Height + 6);
        }
        #endregion

        #region 功能事件

        private void TabControl2_ControlAdded(object sender, ControlEventArgs e)
        {
            if (e.Control.Name == "tp_EmployeeManagement")
            {
                this.dgv_EmployeeManagement.DataSource = EmployeeManagement.SelectALLSalesman();
                this.dgv_EmployeeManagement.Rows[0].Selected = true;
            }
        }

        private void dgv_EmployeeManagement_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            Debug.WriteLine(this.dgv_EmployeeManagement.Rows[e.RowIndex].Cells.Count);
            try
            {
                SetSalesmanInfo(
               this.dgv_EmployeeManagement.Rows[e.RowIndex].Cells["cm_EmployeeManagement_ename"].Value.ToString(),
               this.dgv_EmployeeManagement.Rows[e.RowIndex].Cells["cm_EmployeeManagement_pnum"].Value.ToString(),
               this.dgv_EmployeeManagement.Rows[e.RowIndex].Cells["cm_EmployeeManagement_se"].Value.ToString(),
               this.dgv_EmployeeManagement.Rows[e.RowIndex].Cells["cm_EmployeeManagement_BasePay"].Value.ToString(),
               this.dgv_EmployeeManagement.Rows[e.RowIndex].Cells["cm_EmployeeManagement_per"].Value.ToString(),
               this.dgv_EmployeeManagement.Rows[e.RowIndex].Cells["cm_EmployeeManagement_ro"].Value.ToString());
            }
            catch (Exception)
            { }
        }

        private void dgv_CommodityClassification_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                this.tb_CommodityClassification_TypeName.Text = this.dgv_CommodityClassification.Rows[e.RowIndex].Cells["cm_CommodityClassification_TypeName"].Value.ToString();
            }
            catch (Exception)
            { return; }

            if (this.dgv_CommodityClassification.Rows[e.RowIndex].Cells["cm_CommodityClassification_ParentID"].Value.ToString() == "0")
            {
                this.cb_CommodityClassification_ParentType.SelectedIndex = 0;
                return;
            }

            for (int i = 1; i < this.cb_CommodityClassification_ParentType.Items.Count; i++)
            {
                Models.ComboxItem item = (Models.ComboxItem)this.cb_CommodityClassification_ParentType.Items[i];
                if (item.ID.Equals(this.dgv_CommodityClassification.Rows[e.RowIndex].Cells["cm_CommodityClassification_ParentID"].Value.ToString()))
                {
                    this.cb_CommodityClassification_ParentType.SelectedIndex = i;
                    return;
                }
            }
        }

        private void TabControl2_TabePageClosed(object sender, TabPageEventArgs e)
        {
            if (!this.TabControl2.TabPages.Contains(this.tp_HomePage))
            {
                this.TabControl2.TabPages.Insert(0, this.tp_HomePage);
            }
        }

        private void cb_GoodsBrowse_FirstClassification_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.cb_GoodsBrowse_SecondaryClassification.Enabled = this.cb_GoodsBrowse_FirstLevelClassification.SelectedIndex != 0;
            this.SetGuideComboxInfo();
            this.cb_GoodsBrowse_SecondaryClassification.SelectedIndex = 0;
        }

        private void timer_tik_Tick(object sender, EventArgs e)
        {
            DateTime now = DateTime.Now;
            string week = string.Empty;
            switch ((int)now.DayOfWeek)
            {
                case 0: week = "天"; break;
                case 1: week = "一"; break;
                case 2: week = "二"; break;
                case 3: week = "三"; break;
                case 4: week = "四"; break;
                case 5: week = "五"; break;
                case 6: week = "六"; break;
                default:
                    break;
            }
            this.label_NowTime.Text = $"{now.Year}年{now.Month}月{now.Day}日 星期{week} {now.ToLongTimeString()}";
        }

        private void TabControl2_Selecting(object sender, TabControlCancelEventArgs e)
        {
            if (e.TabPage == null)
            {
                return;
            }
            if (e.TabPage.Name == "tp_GoodsBrowse")
            {
                this.cb_GoodsBrowse_FirstLevelClassification.Items.Clear();
                this.cb_GoodsBrowse_FirstLevelClassification.Items.Add(new Models.ComboxItem() { Text = "全部", ID = "0" });
                this.cb_GoodsBrowse_FirstLevelClassification.Items.AddRange(DBSelect.GoodsClassIfication.GetParentTypes());
                this.cb_GoodsBrowse_FirstLevelClassification.SelectedIndex = 0;
            }
            if (e.TabPage.Name == "tp_CommodityClassification")
            {
                this.dgv_CommodityClassification.Focus();
                this.dgv_CommodityClassification.Rows[0].Selected = true;
                this.AcceptButton = this.bt_CommodityClassification_SaveChange;
            }
            if (e.TabPage.Name == "tp_EmployeeManagement")
            {
                this.dgv_EmployeeManagement.Focus();
                this.dgv_EmployeeManagement.Rows[0].Selected = true;
                this.AcceptButton = this.bt_EmployeeManagement_UpdateInfo;
            }
        }

        private void cb_EmployeeManagement_Gender_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                this.dgv_EmployeeManagement.SelectedRows[0].Cells["cm_EmployeeManagement_se"].Value = this.cb_EmployeeManagement_Sex.Text;
            }
            catch (Exception)
            { }
        }

        private void cb_EmployeeManagement_Role_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                this.dgv_EmployeeManagement.SelectedRows[0].Cells["cm_EmployeeManagement_ro"].Value = this.cb_EmployeeManagement_Role.Text;
            }
            catch (Exception)
            {
            }

        }

        private void cb_CommodityClassification_ParrentType_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                string id = ((Models.ComboxItem)this.cb_CommodityClassification_ParentType.Items[this.cb_CommodityClassification_ParentType.SelectedIndex]).ID;
                this.dgv_CommodityClassification.SelectedRows[0].Cells["cm_CommodityClassification_ParentID"].Value = id;
            }
            catch (Exception)
            { }
        }

        private void cb_WageAccounting_QuickSelection_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.SetDateDnterval(this.dt_WageAccounting_StartDate, this.dt_WageAccounting_EndDate, this.cb_WageAccounting_QuickSelection.Text);
        }

        private void cb_SalesStatistics_QuickSelection_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.SetDateDnterval(this.dt_SalesStatistics_StartDate, this.dt_SalesStatistics_EndDate, this.cb_SalesStatistics_QuickSelection.Text);
        }

        private void cb_GoodsBrowse_QuickSelection_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.SetDateDnterval(this.dt_GoodsBrowse_StartDate, this.dt_GoodsBrowse_EndDate, this.cb_GoodsBrowse_QuickSelection.Text);
        }

        private void lv_ColumAvg_SizeChanged(object sender, EventArgs e)
        {
            SkinListView view = sender as SkinListView;
            view.AutoResizeColumn(0, ColumnHeaderAutoResizeStyle.HeaderSize);
            int avgWidth = (view.Width - view.Columns[0].Width) / view.Columns.Count - 1;
            for (int i = 1; i < view.Columns.Count; i++)
            {
                view.Columns[i].Width = avgWidth;
            }
        }

        private void SkinTxt_NumberCheck_KeyPress(object sender, KeyPressEventArgs e)
        {
            if ((int)e.KeyChar == (int)Keys.Back) return;
            if (char.IsNumber(e.KeyChar)) return;
            e.Handled = true;
        }

        private void SkinTxt_DecimalCheck_KeyPress(object sender, KeyPressEventArgs e)
        {
            if ((int)e.KeyChar == (int)Keys.Decimal) return;
            if ((int)e.KeyChar == (int)Keys.Delete) return;
            if ((int)e.KeyChar == (int)Keys.Back) return;
            if (char.IsNumber(e.KeyChar)) return;
            e.Handled = true;
        }

        private void SkinTxt_TextChanged(object sender, EventArgs e)
        {
            TextBox box = sender as TextBox;
            try
            {
                switch (box.Name)
                {
                    case "tb_CommodityClassification_TypeNameTB":
                        this.dgv_CommodityClassification.SelectedRows[0].Cells["cm_CommodityClassification_TypeName"].Value = box.Text; break;
                    case "tb_EmployeeManagement_BasePayTB":
                        this.dgv_EmployeeManagement.SelectedRows[0].Cells["cm_EmployeeManagement_BasePay"].Value = box.Text; break;
                    case "tb_EmployeeManagement_NameTB":
                        this.dgv_EmployeeManagement.SelectedRows[0].Cells["cm_EmployeeManagement_ename"].Value = box.Text; break;
                    case "tb_EmployeeManagement_PhoneNumberTB":
                        this.dgv_EmployeeManagement.SelectedRows[0].Cells["cm_EmployeeManagement_pnum"].Value = box.Text; break;
                    case "tb_EmployeeManagement_CommissionRatioTB":
                        this.dgv_EmployeeManagement.SelectedRows[0].Cells["cm_EmployeeManagement_per"].Value = box.Text; break;
                    default:
                        break;
                }
            }
            catch (Exception)
            { }
        }

        #endregion

        #region 按钮点击事件
        private void bt_TabBinding_Click(object sender, EventArgs e)
        {
            SkinButton bt = sender as SkinButton;
            TabPage page = bt.Tag as TabPage;

            if (User.Role == Positions.收银员)
            {
                Methods.ShowPrompt("没有足够的权限",1000);
                return;
            }
            if (User.Role==Positions.导购员)
            {
                if (bt.Name!="bt_Cashier"&& bt.Name!= "bt_GoodsInsrt" && bt.Name!="bt_GoodsBrowse" && bt.Name != "bt_CommodityClassification")
                {
                    Methods.ShowPrompt("没有足够的权限",1000);
                    return;
                }
            }

            if (!this.TabControl2.TabPages.Contains(page))
            {
                this.TabControl2.TabPages.Add(page);
            }
            this.TabControl2.SelectedTab = page;
        }

        private void bt_GoodsBrowse_QueryBtn_Click(object sender, EventArgs e)
        {
            #region 获取约束条件
            string barCode = this.tb_GoodsBrowse_ArticleNo.Text.Length == 0 ? "全部" : this.tb_GoodsBrowse_ArticleNo.Text;
            string name = this.tb_GoodsBrowse_GoodsName.Text.Length == 0 ? "全部" : this.tb_GoodsBrowse_GoodsName.Text;
            Models.ComboxItem type1 = (Models.ComboxItem)this.cb_GoodsBrowse_FirstLevelClassification.Items[this.cb_GoodsBrowse_FirstLevelClassification.SelectedIndex];
            Models.ComboxItem type2 = (Models.ComboxItem)this.cb_GoodsBrowse_SecondaryClassification.Items[this.cb_GoodsBrowse_SecondaryClassification.SelectedIndex];
            DateTime start = this.dt_GoodsBrowse_StartDate.Value;
            DateTime end = this.dt_GoodsBrowse_EndDate.Value;

            #endregion

            #region 显示结果
            this.lv_GoodsBrowse_QueryResults.Items.Clear();
            this.lv_GoodsBrowse_QueryResults.Items.AddRange(GoodsBrowse.GoodsSelect(start, end, type1, type2, barCode, name).ToArray());
            this.lb_GoodsBrowse_DataStatistics.Text = $"共检索到{this.lv_GoodsBrowse_QueryResults.Items.Count}条数据";
            #endregion
        }

        private void bt_SalesStatistics_Query_Click(object sender, EventArgs e)
        {
            #region 获取约束条件
            DateTime start = dt_SalesStatistics_StartDate.Value;
            DateTime end = dt_SalesStatistics_EndDate.Value;
            string guide = cb_SalesStatistics_Guide.Text;

            #endregion

            #region 显示结果
            Task.Run(() =>
            {
                this.lv_SalesStatistics_QueryResults.Items.Clear();
                double amount = 0;
                double profit = 0;
                List<ListViewItem> listViewItems = SalesQuery.SalesRecordSelect(guide, start, end);
                foreach (var item in listViewItems)
                {
                    amount += double.Parse(item.SubItems[3].Text);
                    profit += double.Parse(item.SubItems[4].Text);
                }
                this.lv_SalesStatistics_QueryResults.Items.AddRange(listViewItems.ToArray());
                this.lb_SalesStatistics_Count.Text = "查询到销售记录" + listViewItems.Count + "条";
                this.lb_SalesStatistics_Amount.Text = $"销售金额¥{amount.ToString("#0.00")}元,销售利润¥{profit.ToString("#0.00")}元";
            });
            #endregion
        }

        private void bt_Cashier_Click(object sender, EventArgs e)
        {
            this.Hide();
            new CashierForm(this.User).ShowDialog();
            this.Show();
        }

        private void bt_WageAccounting_AccountingButton_Click(object sender, EventArgs e)
        {
            DateTime start = this.dt_WageAccounting_StartDate.Value;
            DateTime end = this.dt_WageAccounting_EndDate.Value;
            List<ListViewItem> list = DBSelect.WageAccount.SelectAllSalesman(start, end);
            this.lv_WageAccounting_QueryResults.Items.Clear();
            this.lv_WageAccounting_QueryResults.Items.AddRange(list.ToArray());
        }

        private void bt_CommodityClassification_Save_Click(object sender, EventArgs e)
        {
            this.dgv_CommodityClassification.CurrentCell = null;
            GoodsClassIfication.UpdateTable();
            Methods.ShowPrompt("操作完成", 1500);
        }

        private void bt_CommodityClassification_NewAdd_Click(object sender, EventArgs e)
        {
            AddTypeForm f = new AddTypeForm();
            f.ShowDialog();
            f.Dispose();
            this.dgv_CommodityClassification.DataSource = DBSelect.GoodsClassIfication.SelectAllTypes();
            this.dgv_CommodityClassification.Rows[0].Selected = true;
            this.tb_CommodityClassification_TypeName.Text = this.dgv_CommodityClassification.Rows[0].Cells["cm_CommodityClassification_TypeName"].Value.ToString();
        }

        private void bt_EmployeeManagement_ChangeInfoBtn_Click(object sender, EventArgs e)
        {
            //this.dgv_EmployeeManagement.EndEdit();
            this.dgv_EmployeeManagement.CurrentCell = null;
            EmployeeManagement.UpdateSalesmanInfo();
            Methods.ShowPrompt(" 操作完成", 1500);
            this.dgv_EmployeeManagement.DataSource = EmployeeManagement.SelectALLSalesman();
            SetSalesmanInfo(
                this.dgv_EmployeeManagement.SelectedRows[0].Cells["cm_EmployeeManagement_ename"].Value.ToString(),
                this.dgv_EmployeeManagement.SelectedRows[0].Cells["cm_EmployeeManagement_pnum"].Value.ToString(),
                this.dgv_EmployeeManagement.SelectedRows[0].Cells["cm_EmployeeManagement_se"].Value.ToString(),
                this.dgv_EmployeeManagement.SelectedRows[0].Cells["cm_EmployeeManagement_BasePay"].Value.ToString(),
                this.dgv_EmployeeManagement.SelectedRows[0].Cells["cm_EmployeeManagement_per"].Value.ToString(),
                this.dgv_EmployeeManagement.SelectedRows[0].Cells["cm_EmployeeManagement_ro"].Value.ToString());
        }

        private void bt_GoodsWarehousing_Click(object sender, EventArgs e)
        {
            if (User.Role==Positions.收银员)
            {
                Methods.ShowPrompt("没有足够的权限",1000);
                return;
            }
            new GoodsWarehousForm().ShowDialog();
        }

        private void bt_UserInfo_Click(object sender, EventArgs e)
        {
            string info = $"员工编号: {User.UserID.PadLeft(4, '0')}\n" +
                 $"登陆账号: {User.LoginID}\n" +
                $"姓名: {User.UserName}\n" +
                $"性别: {User.Gender}\n" +
                $"身份: {User.Role}";
            MessageBox.Show(info, "用户信息");
        }

        private void bt_ReturnGoods_Click(object sender, EventArgs e)
        {
            if (User.Role!=Positions.店长)
            {
                Methods.ShowPrompt("没有足够的权限",1000);
                return;
            }

            new RetGoodsForm().ShowDialog();
        }

        #endregion

        #region 函数
        /// <summary>
        /// 必要的控件属性初始化
        /// </summary>
        private void Initialize()
        {
            //获取子父类Item数据
            this.cb_GoodsBrowse_FirstLevelClassification.Items.Add(new Models.ComboxItem() { Text = "全部", ID = "0" });
            this.cb_GoodsBrowse_FirstLevelClassification.Items.AddRange(DBSelect.GoodsClassIfication.GetParentTypes());

            this.cb_GoodsBrowse_SecondaryClassification.Items.Add(new Models.ComboxItem() { Text = "全部", ID = "0" });
            this.cb_GoodsBrowse_SecondaryClassification.Items.AddRange(DBSelect.GoodsClassIfication.GetSubTypes(this.cb_GoodsBrowse_FirstLevelClassification.Text));

            //设置初始选中索引
            this.cb_GoodsBrowse_FirstLevelClassification.SelectedIndex = 0;
            this.cb_GoodsBrowse_SecondaryClassification.SelectedIndex = 0;
            this.cb_EmployeeManagement_Role.SelectedIndex = 0;
            this.cb_EmployeeManagement_Sex.SelectedIndex = 0;


            this.SetGuideComboxInfo();
            this.cb_SalesStatistics_Guide.Items.Add("全部");
            this.cb_SalesStatistics_Guide.Items.AddRange(DBSelect.Guides);
            this.cb_SalesStatistics_Guide.SelectedIndex = 0;

            this.tb_EmployeeManagement_BasePay.SkinTxt.KeyPress += SkinTxt_DecimalCheck_KeyPress;
            this.tb_EmployeeManagement_CommissionRatio.SkinTxt.KeyPress += SkinTxt_DecimalCheck_KeyPress;
            this.tb_EmployeeManagement_PhoneNumber.SkinTxt.KeyPress += SkinTxt_NumberCheck_KeyPress;
            this.tb_GoodsBrowse_ArticleNo.SkinTxt.KeyPress += SkinTxt_NumberCheck_KeyPress;

            this.tb_CommodityClassification_TypeName.SkinTxt.Name = "tb_CommodityClassification_TypeNameTB";
            this.tb_EmployeeManagement_BasePay.SkinTxt.Name = "tb_EmployeeManagement_BasePayTB";
            this.tb_EmployeeManagement_Name.SkinTxt.Name = "tb_EmployeeManagement_NameTB";
            this.tb_EmployeeManagement_PhoneNumber.SkinTxt.Name = "tb_EmployeeManagement_PhoneNumberTB";
            this.tb_EmployeeManagement_CommissionRatio.SkinTxt.Name = "tb_EmployeeManagement_CommissionRatioTB";

            this.tb_CommodityClassification_TypeName.SkinTxt.TextChanged += SkinTxt_TextChanged;
            this.tb_EmployeeManagement_BasePay.SkinTxt.TextChanged += SkinTxt_TextChanged;
            this.tb_EmployeeManagement_Name.SkinTxt.TextChanged += SkinTxt_TextChanged;
            this.tb_EmployeeManagement_PhoneNumber.SkinTxt.TextChanged += SkinTxt_TextChanged;
            this.tb_EmployeeManagement_CommissionRatio.SkinTxt.TextChanged += SkinTxt_TextChanged;

            this.cb_GoodsBrowse_QuickSelection.SelectedIndex = 0;
            this.cb_WageAccounting_QuickSelection.SelectedIndex = 0;
            this.cb_SalesStatistics_QuickSelection.SelectedIndex = 0;

            this.cb_CommodityClassification_ParentType.Items.Add(new Models.ComboxItem() { Text = "无", ID = "0" });
            this.cb_CommodityClassification_ParentType.Items.AddRange(DBSelect.GoodsClassIfication.GetParentTypes());
            this.cb_CommodityClassification_ParentType.SelectedIndex = 0;

            this.dgv_CommodityClassification.DataSource = DBSelect.GoodsClassIfication.SelectAllTypes();
            this.dgv_CommodityClassification.Rows[0].Selected = true;
            this.tb_CommodityClassification_TypeName.Text = this.dgv_CommodityClassification.Rows[0].Cells["cm_CommodityClassification_TypeName"].Value.ToString();

            int count = this.TabControl2.TabPages.Count - 1;
            for (int i = 0; i < count; i++)
            {
                this.TabControl2.TabPages.RemoveAt(1);
            }
        }

        /// <summary>
        /// 设置商品二级下拉列表值
        /// </summary>
        public void SetGuideComboxInfo()
        {
            if (this.cb_GoodsBrowse_FirstLevelClassification.SelectedIndex == 0)
            {
                return;
            }
            this.cb_GoodsBrowse_SecondaryClassification.Items.Clear();
            this.cb_GoodsBrowse_SecondaryClassification.Items.Add(new Models.ComboxItem() { Text = "全部", ID = "0" });
            this.cb_GoodsBrowse_SecondaryClassification.Items.AddRange(DBSelect.GoodsClassIfication.GetSubTypes(this.cb_GoodsBrowse_FirstLevelClassification.Text));
        }

        /// <summary>
        /// 设置DateTimePicker的值区间
        /// </summary>
        /// <param name="start">表示StartDate的控件</param>
        /// <param name="end">表示结束时间的控件</param>
        /// <param name="value">QuickSelection下拉选项参数</param>
        private void SetDateDnterval(DateTimePicker start, DateTimePicker end, string value)
        {
            DateTime now = DateTime.Now;
            int dayofMonth = now.Day;

            switch (value)
            {
                case "本日":
                    start.Value = now;
                    end.Value = now;
                    break;

                case "本周":
                    int dayofWeek = (int)now.DayOfWeek;
                    if (dayofWeek == 0) dayofWeek = 7;
                    start.Value = now.AddDays(-dayofWeek + 1);
                    end.Value = now.AddDays(-dayofWeek + 1 + 6);
                    break;

                case "本月":
                    start.Value = now.AddDays(-dayofMonth + 1);
                    end.Value = now.AddDays(-dayofMonth + 1).AddMonths(1).AddDays(-1);
                    break;

                case "上月":
                    start.Value = now.AddDays(-dayofMonth + 1).AddMonths(-1);
                    end.Value = now.AddDays(-dayofMonth);
                    break;

                case "本年":
                    int dofy = now.DayOfYear;
                    start.Value = now.AddDays(-dofy + 1);
                    end.Value = now.AddDays(-dofy + 1).AddYears(1).AddDays(-1);
                    break;
                default:
                    throw new Exception("值传入错误!没有<" + value + ">选项");
            }
        }

        /// <summary>
        /// 设置当前EmployeeManagement信息面板的信息
        /// </summary>
        /// <param name="name">EmployeeName</param>
        /// <param name="mob">电话号码</param>
        /// <param name="sex">性别</param>
        /// <param name="salary">BasePay</param>
        /// <param name="comm">CommissionRatio</param>
        /// <param name="role">员工角色</param>
        private void SetSalesmanInfo(string name, string mob, string sex, string salary, string comm, string role)
        {
            this.tb_EmployeeManagement_Name.Text = name;
            this.tb_EmployeeManagement_PhoneNumber.Text = mob;
            this.tb_EmployeeManagement_CommissionRatio.Text = comm;
            this.tb_EmployeeManagement_BasePay.Text = salary;
            this.cb_EmployeeManagement_Sex.SelectedIndex = (sex == "男" ? 0 : 1);
            this.cb_EmployeeManagement_Role.SelectedIndex = (role == "收银员" ? 0 : role == "导购员" ? 1 : 2);
        }
        #endregion
    }
}
